#ifdef PBC_CONSTANTPOOL_ENTRY

/// scope
BytecodeArrayBuilder& BytecodeArrayBuilder::CreateBlockContext(
    size_t scope_index) {
  OutputCreateBlockContext(scope_index);
  return *this;
}

BytecodeArrayBuilder& BytecodeArrayBuilder::CreateCatchContext(
    Register exception, size_t scope_index) {
  OutputCreateCatchContext(exception, scope_index);
  return *this;
}

BytecodeArrayBuilder& BytecodeArrayBuilder::CreateFunctionContext(
    size_t scope_index, int slots) {
  OutputCreateFunctionContext(scope_index, slots);
  return *this;
}

BytecodeArrayBuilder& BytecodeArrayBuilder::CreateEvalContext(
    size_t scope_index, int slots) {
  OutputCreateEvalContext(scope_index, slots);
  return *this;
}

BytecodeArrayBuilder& BytecodeArrayBuilder::CreateWithContext(
    Register object, size_t scope_index) {
  OutputCreateWithContext(object, scope_index);
  return *this;
}

/// AstRawString*

BytecodeArrayBuilder& BytecodeArrayBuilder::LoadGlobal(size_t name_index,
                                                       int feedback_slot,
                                                       TypeofMode typeof_mode) {
  // Ensure that typeof mode is in sync with the IC slot kind.
  DCHECK_EQ(GetTypeofModeFromSlotKind(feedback_vector_spec()->GetKind(
                FeedbackVector::ToSlot(feedback_slot))),
            typeof_mode);
  switch (typeof_mode) {
    case TypeofMode::kInside:
      OutputLdaGlobalInsideTypeof(name_index, feedback_slot);
      break;
    case TypeofMode::kNotInside:
      OutputLdaGlobal(name_index, feedback_slot);
      break;
  }
  return *this;
}

BytecodeArrayBuilder& BytecodeArrayBuilder::StoreGlobal(size_t name_index,
                                                        int feedback_slot) {
  OutputStaGlobal(name_index, feedback_slot);
  return *this;
}

BytecodeArrayBuilder& BytecodeArrayBuilder::LoadLookupSlot(
    size_t name_index, TypeofMode typeof_mode) {
  switch (typeof_mode) {
    case TypeofMode::kInside:
      OutputLdaLookupSlotInsideTypeof(name_index);
      break;
    case TypeofMode::kNotInside:
      OutputLdaLookupSlot(name_index);
      break;
  }
  return *this;
}

#if V8_MAJOR_VERSION == 11
BytecodeArrayBuilder& BytecodeArrayBuilder::LoadLookupContextSlot(
    size_t name_index, TypeofMode typeof_mode, int slot_index, int depth) {
  switch (typeof_mode) {
    case TypeofMode::kInside:
      OutputLdaLookupContextSlotInsideTypeof(name_index, slot_index, depth);
      break;
    case TypeofMode::kNotInside:
      OutputLdaLookupContextSlot(name_index, slot_index, depth);
      break;
  }
  return *this;
}
#else

BytecodeArrayBuilder& BytecodeArrayBuilder::LoadLookupContextSlot(
    size_t name_index, TypeofMode typeof_mode, ContextKind context_kind,
    int slot_index, int depth) {
  switch (typeof_mode) {
    case TypeofMode::kInside:
      if (v8_flags.script_context_mutable_heap_number &&
          context_kind == ContextKind::kScriptContext) {
        OutputLdaLookupScriptContextSlotInsideTypeof(name_index, slot_index,
                                                     depth);
      } else {
        OutputLdaLookupContextSlotInsideTypeof(name_index, slot_index, depth);
      }
      break;
    case TypeofMode::kNotInside:
      if (v8_flags.script_context_mutable_heap_number &&
          context_kind == ContextKind::kScriptContext) {
        OutputLdaLookupScriptContextSlot(name_index, slot_index, depth);
      } else {
        OutputLdaLookupContextSlot(name_index, slot_index, depth);
      }
      break;
  }
  return *this;
}

#endif

BytecodeArrayBuilder& BytecodeArrayBuilder::LoadLookupGlobalSlot(
    size_t name_index, TypeofMode typeof_mode, int feedback_slot, int depth) {
  switch (typeof_mode) {
    case TypeofMode::kInside:
      OutputLdaLookupGlobalSlotInsideTypeof(name_index, feedback_slot, depth);
      break;
    case TypeofMode::kNotInside:
      OutputLdaLookupGlobalSlot(name_index, feedback_slot, depth);
      break;
  }
  return *this;
}

BytecodeArrayBuilder& BytecodeArrayBuilder::StoreLookupSlot(
    size_t name_index, LanguageMode language_mode,
    LookupHoistingMode lookup_hoisting_mode) {
  uint8_t flags =
      StoreLookupSlotFlags::Encode(language_mode, lookup_hoisting_mode);
  OutputStaLookupSlot(name_index, flags);
  return *this;
}

BytecodeArrayBuilder& BytecodeArrayBuilder::LoadNamedProperty(
    Register object, size_t name_index, int feedback_slot) {
  OutputGetNamedProperty(object, name_index, feedback_slot);
  return *this;
}

BytecodeArrayBuilder& BytecodeArrayBuilder::DefineNamedOwnProperty(
    Register object, size_t name_index, int feedback_slot) {
  // Ensure that the store operation is in sync with the IC slot kind.
  DCHECK_EQ(
      FeedbackSlotKind::kDefineNamedOwn,
      feedback_vector_spec()->GetKind(FeedbackVector::ToSlot(feedback_slot)));
  OutputDefineNamedOwnProperty(object, name_index, feedback_slot);
  return *this;
}

BytecodeArrayBuilder& BytecodeArrayBuilder::CreateRegExpLiteral(
    size_t pattern_entry, int literal_index, int flags) {
  OutputCreateRegExpLiteral(pattern_entry, literal_index, flags);
  return *this;
}

BytecodeArrayBuilder& BytecodeArrayBuilder::ThrowReferenceErrorIfHole(
    size_t entry) {
  OutputThrowReferenceErrorIfHole(entry);
  return *this;
}

BytecodeArrayBuilder& BytecodeArrayBuilder::CallProperty(
    Register callable, std::vector<Register> args, int feedback_slot) {
  DCHECK_LE(args.size(), 3);
  if (args.size() == 1) {
    OutputCallProperty0(callable, args[0], feedback_slot);
  } else if (args.size() == 2) {
    OutputCallProperty1(callable, args[0], args[1], feedback_slot);
  } else if (args.size() == 3) {
    OutputCallProperty2(callable, args[0], args[1], args[2], feedback_slot);
  } else {
    UNREACHABLE();
  }
  return *this;
}

BytecodeArrayBuilder& BytecodeArrayBuilder::CallUndefinedReceiver(
    Register callable, std::vector<Register> args, int feedback_slot) {
  DCHECK_LE(args.size(), 2);
  if (args.size() == 0) {
    OutputCallUndefinedReceiver0(callable, feedback_slot);
  } else if (args.size() == 1) {
    OutputCallUndefinedReceiver1(callable, args[0], feedback_slot);
  } else if (args.size() == 2) {
    OutputCallUndefinedReceiver2(callable, args[0], args[1], feedback_slot);
  } else {
    UNREACHABLE();
  }
  return *this;
}

#endif